package com.javaspeak.designpatterns.go4.behavioural.observer;

/**
 * The class which is having its state observed implements this interface.
 * <p>
 * When a certain event happens the Observable will notify all its subscribed
 * observers that the event has occurred.
 *
 * @author John Dickerson
 */
public interface Observable {

    /**
     * Add a subscribed observer to its list of observers.  The subscribed
     * observers can be said from that point in time to be listening to
     * ObservableEvents.
     *
     * @param observer The observer which has subscribed to the
     * ObservableEvents
     */
    public void addObserver( Observer observer );

    /**
     * The Observable calls this method to inform all its subscribed observers
     * that an ObservableEvent has occurred.
     *
     * @param observableEvent The ObservableEvent to inform all its subscribed
     * observers that it has occurred. Internally the notifyObservers(..) method
     * loops through all its subscribed observers and calls the
     * receiveObservableEvent(..) method on each of them. Each of the subscribed
     * observers in turn calls the getMessage() method on the ObservableEvent
     * they received and prints the message to the console.
     */
    public void notifyObservers( ObservableEvent observableEvent );
}
